class Solution(object):
    def rotate(self, matrix):
        """
        :type matrix: List[List[int]]
        :rtype: void Do not return anything, modify matrix in-place instead.
        """
        def rot(up, down, left, right):
            for i in range(down-up):
                upleft = matrix[up][left+i]
                upright = matrix[up+i][right]
                downright = matrix[down][right-i]
                downleft = matrix[down-i][left]
                matrix[up+i][right]=upleft
                matrix[down][right-i]=upright
                matrix[down-i][left]=downright
                matrix[up][left+i]=downleft
        for i in range(len(matrix)//2):
            up, down, left, right = i, len(matrix)-i-1, i, len(matrix)-i-1
            rot(up, down, left, right)

matrix = [
    [1,2],
    [3,4],
]

Solution().rotate(matrix)
print(matrix)